package action;

import bean.Department;
import dao.DepartmentDAO;
import dao.DepartmentDAOImpl;
import tools.HibernateSessionFactory;

import java.util.List;

public class DepartmentAction {
    private DepartmentDAO departmentDAO = new DepartmentDAOImpl(HibernateSessionFactory.getSession());
    private List<Department> departments;
    private Department department;

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public List<Department> getDepartments() {
        return departments;
    }

    public String execute() {
        departments = departmentDAO.queryAll();
        return "success";
    }

    public String add() {
        return departmentDAO.add(department) ? "add" : null;
    }

    public String edit() {
        department = departmentDAO.query(department.getDepartmentId());
        return "edit";
    }

    public String modify() {
        return departmentDAO.modify(department) ? "modify" : null;
    }

    public String remove() {
        return departmentDAO.remove(department.getDepartmentId()) ? "remove" : null;
    }
}
